// pages/newsdetail/newsdetail.js
import cache from '../../utils/Cache.js';
import url from '../../utils/url.js';
import http from '../../utils/http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
      articleDetail : {}
  },

  /**
   * 生命周期函数--监听页面加载
   * https://blog.csdn.net/qq_36423639/article/details/80403269
   * 解决富文本显示信息
   * <rich-text nodes="{{ articleDetail.body }}"></rich-text>
   */
  onLoad: function (options) {
    let that = this;
    let id = options.id;
    that.getArticleDetail(id);
	that.articleCount(id);
  },
  
  //查询订单详情信息
  getArticleDetail:function(id){
	  let that = this;
	  http.http(url.articleDetail+'/'+id,'GET',{},function(res){
	    console.log(res)
	      that.setData({
	        articleDetail:res
	      });
	  });
  },
  
  //统计文章的访问人数
  articleCount:function(id){
	  http.http(url.articleCount,'POST',{openid:cache.getSorg('openid'),art_id:id},function(res){
		  console.log(res);
	  });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   * https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onshareappmessageobject-object
   */
  onShareAppMessage: function (res) {
    let that = this
      return {
        title: that.articleDetail.title,
        path:'/pages/newsdetail/newsdetail?id='+ that.articleDetail.id,
        imageUrl:that.data.pic
      }
  }
})